package pl.iachoo.ctl.tabory.dao.ibatis.services.impl;

import java.util.List;

import org.apache.log4j.Logger;

import com.ibatis.sqlmap.client.SqlMapClient;

import pl.iachoo.ctl.tabory.dao.api.services.IUserRoleService;
import pl.iachoo.ctl.tabory.dao.data.vo.UserRoleVO;
import pl.iachoo.ctl.tabory.dao.ibatis.services.BaseDaoService;

public class UserRoleDaoServiceImpl extends BaseDaoService implements
		IUserRoleService {

	private final Logger logger = Logger
			.getLogger(UserRoleDaoServiceImpl.class);

	private final static String MAPPER = "map-user-roles";

	public UserRoleDaoServiceImpl(SqlMapClient sqlMapClient) {
		super(sqlMapClient);
	}

	@Override
	@SuppressWarnings("unchecked")
	public List<UserRoleVO> getAllUserRoles() throws Exception {
		logger.debug("Getting all user roles");
		sqlMapClient.startTransaction();
		List<UserRoleVO> list = sqlMapClient.queryForList(MAPPER
				+ ".selectAllUserRoles");
		sqlMapClient.commitTransaction();
		logger.debug(list);
		return list;
	}

	@Override
	public UserRoleVO getUserRole(Long userRoleId) throws Exception {
		logger.debug("Getting user role for id: " + userRoleId);
		sqlMapClient.startTransaction();
		UserRoleVO role = (UserRoleVO) sqlMapClient.queryForObject(MAPPER
				+ ".selectUserRole", userRoleId);
		sqlMapClient.commitTransaction();
		logger.debug(role);
		return role;
	}

}
